package com.orangelife.mobile.surrounding.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.curry.android.adapter.FatherAdapter;
import com.curry.orangelife.mobile.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/4/5.
 */
public class GoodListLeftAdapter<T> extends FatherAdapter<T> {

    private Context context;
    private  List<T> mlist=new ArrayList<T>();
    private boolean key=true;
    LinearLayout headll=null;
    TextView headtv=null;
    private int colorItem=0;
    private Map<Integer,LinearLayout> llMap=new HashMap<Integer,LinearLayout>();
    public GoodListLeftAdapter(Context context, List<T> list) {
        this.context = context;
        this.mlist = list;
    }

    @Override
    public BaseAdapter setList(List<T> list) {
        this.mlist=list;
        return GoodListLeftAdapter.this;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_left_button, null);
            holder.tvName= (TextView) convertView.findViewById(R.id.tv_active);
            holder.llOnClick=(LinearLayout)convertView.findViewById(R.id.ll_botton);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        Map<String,String> map=(Map<String,String>)mlist.get(position);
        holder.tvName.setText(map.get("catName"));
        if(key&&position==0){
            holder.llOnClick.setBackgroundResource(R.color.white);
            holder.tvName.setTextColor(Color.parseColor("#fff57c24"));
            headll=holder.llOnClick;
            headtv=holder.tvName;
            key=false;
        }

        llMap.put(position,holder.llOnClick);

        return convertView;
    }

    class ViewHolder {

        /**
         * 标题
         */
        private TextView tvName;
        /**
         * 点击事件
         */
        private LinearLayout llOnClick;


    }
    public void setHeaderView(){
        headll.setBackgroundResource(R.color.InputGray);
        headtv.setTextColor(Color.parseColor("#535353"));

    }
    public void setReplaceColorItem(int position){
        this.colorItem=position;
    }

    public void setColorItem(int position){
        for(int i=0;i<llMap.size();i++){
            LinearLayout ll=llMap.get(i);
            if(position==i) {

                TextView tv = (TextView) ll.getChildAt(0);
                ll.setBackgroundResource(R.color.white);
                tv.setTextColor(Color.parseColor("#fff57c24"));
            }else{
                TextView tv = (TextView) ll.getChildAt(0);
                ll.setBackgroundResource(R.color.InputGray);
                tv.setTextColor(Color.parseColor("#535353"));
            }
        }
    }
}
